package com.blrs.controller;

import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableDataInfo;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.enums.BusinessType;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.domain.*;
import com.blrs.domain.vo.BusinessMainClassVo;
import com.blrs.service.project.info.IProjectInfoService;
import com.blrs.service.project.schedule.IProjectScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 项目进度信息 Controller
 * 
 * @author ruoyi
 * @date 2023-11-30
 */
@RestController
@RequestMapping("/project/projectSchedule")
public class ProjectScheduleController extends BaseController
{
    @Autowired
    private IProjectInfoService projectInfoService;

    @Autowired
    private IProjectScheduleService projectScheduleService;


    @GetMapping("/listMaxIndex")
    public TableDataInfo listMaxIndex(ProjectSchedule projectSchedule)
    {
        startPage();
        List<ProjectSchedule> list = projectScheduleService.selectProjectScheduleListMaxIndex(projectSchedule);
        return getDataTable(list);
    }

    //根据项目id查询阶段名称
    @GetMapping("/getScheduleName")
    public AjaxResult getScheduleName(ProjectStage projectStage)
    {
        List<Map> list = projectScheduleService.getScheduleName(projectStage);
        return success(list);
    }
    //主子列表
    @GetMapping("/listProjectTree")
    public AjaxResult listProjectTree(ProjectInfo projectInfo, SubProjectInfo subProjectInfo)
    {
        List<Map> list = projectInfoService.getProjectTree(projectInfo,subProjectInfo);
        return success(list);
    }



    /**
     * 查询项目进度列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProjectSchedule projectSchedule)
    {
        startPage();
        List<ProjectSchedule> list = projectScheduleService.selectProjectScheduleList(projectSchedule);
        return getDataTable(list);
    }

    /**
     * 导出项目进度列表
     */
    @Log(title = "项目进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectSchedule projectSchedule)
    {
        List<ProjectSchedule> list = projectScheduleService.selectProjectScheduleList(projectSchedule);
        ExcelUtil<ProjectSchedule> util = new ExcelUtil<ProjectSchedule>(ProjectSchedule.class);
        util.exportExcel(response, list, "项目进度数据");
    }

    /**
     * 获取项目进度详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(projectScheduleService.selectProjectScheduleById(id));
    }

    /**
     * 新增项目进度
     */
    @Log(title = "项目进度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectSchedule projectSchedule)
    {
        return toAjax(projectScheduleService.insertProjectSchedule(projectSchedule));
    }

    /**
     * 修改项目进度
     */
    @Log(title = "项目进度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectSchedule projectSchedule)
    {
        return toAjax(projectScheduleService.updateProjectSchedule(projectSchedule));
    }

    /**
     * 删除项目进度
     */
    @Log(title = "项目进度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(projectScheduleService.deleteProjectScheduleByIds(ids));
    }
}
